#!/bin/sh
#
# This will build and install the debug and release flavors of wxWidgets 3.0.2 for
# use with Audacity.  Just extract the wxWidgets source whereever you like, change
# to that directory and then run this script.
#
arch='-arch i386'
sdk="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk/"

if [ ! -d "${sdk}" ]
then
   echo "You must install the 10.6 SDK at this location:"
   echo "${sdk}"
   exit 1
fi

# Audacity supports Tiger and newer, so limit API usage 10.6
export CPPFLAGS="-DMAC_OS_X_VERSION_MAX_ALLOWED=1060 -mmacosx-version-min=10.6"
export CFLAGS1="$arch -DMAC_OS_X_VERSION_MAX_ALLOWED=1060 -isysroot $sdk -mmacosx-version-min=10.6"
export CXXFLAGS1="$arch -DMAC_OS_X_VERSION_MAX_ALLOWED=1060 -isysroot $sdk -mmacosx-version-min=10.6"
export LDFLAGS1="$arch -DMAC_OS_X_VERSION_MAX_ALLOWED=1060 -syslibroot,$sdk"

# Make sure our flags are included
export CC="gcc $CFLAGS1"
export CXX="g++ $CXXFLAGS1"
export LD="g++ $LDFLAGS1"

# Build a specific configuration
function bld
{
  rm -rf "${1}"
   mkdir -p "${1}"
   pushd "${1}"
   shift
   ../configure --enable-accessibility \
                --disable-compat26 \
                --disable-compat28 \
                --with-expat=builtin \
                --with-zlib=builtin \
                --with-regex=builtin \
                --enable-universal_binary=no \
                --enable-unicode=yes \
                --enable-webkit=no \
                ${@}
   xcrun make -j 4
   popd
}

# Install a specific configuration
function inst
{
   pushd "${1}"
   sudo xcrun make install
   popd
}

# Build all configurations
bld bld_debug --enable-debug=yes --enable-static=no --enable-shared=yes --with-flavour=debug
bld bld_release --enable-debug=no --enable-static=no --enable-shared=yes --with-flavour=release

# Install all configurations
inst bld_debug
inst bld_release
